---
layout: "default"
title: "Equatable"
description: "Swift documentation for 'Equatable': Instances of conforming types can be compared for value equality."
keywords: "Equatable,protocol,swift,documentation,=="
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">protocol Equatable</code></div>

<div class="discussion comment">
    <p>Instances of conforming types can be compared for value equality
using operators <code>==</code> and <code>!=</code>.</p>

<p>When adopting <code>Equatable</code>, only the <code>==</code> operator is required to be
implemented.  The standard library provides an implementation for <code>!=</code>.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>







<h3>Instance Methods</h3>
<div class="declaration" id="func-eqeq_rhs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-eqeq_rhs_">func ==(<wbr>_:<wbr>rhs:)</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-eqeq_rhs_"><div class="p">
    <p>Return true if <code>lhs</code> is equal to <code>rhs</code>.</p>

<p><strong>Equality implies substitutability</strong>.  When <code>x == y</code>, <code>x</code> and
<code>y</code> are interchangeable in any code that only depends on their
values.</p>

<p>Class instance identity as distinguished by triple-equals <code>===</code>
is notably not part of an instance&#39;s value.  Exposing other
non-value aspects of <code>Equatable</code> types is discouraged, and any
that <em>are</em> exposed should be explicitly pointed out in
documentation.</p>

<p><strong>Equality is an equivalence relation</strong></p>

<ul><li><code>x == x</code> is <code>true</code></li><li><code>x == y</code> implies <code>y == x</code></li><li><code>x == y</code> and <code>y == z</code> implies <code>x == z</code></li></ul>

<p><strong>Inequality is the inverse of equality</strong>, i.e. <code>!(x == y)</code> iff
<code>x != y</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">func ==(lhs: Self, rhs: Self) -&gt; Bool</code>
    
    
</div></div>
</div>


